<?php
namespace adminmatrix\migration\command\migrate;

use think\console\input\Option as InputOption;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument as InputArgument;
use think\console\Output;

class Create extends Command
{

    protected function configure(): void
    {
        $this->setName('migrate:create')
            ->addOption('app' , '-a', InputOption::VALUE_OPTIONAL , '要创建的app应用名')
            ->setDescription('创建新的数据库迁移')
            ->addArgument('name', InputArgument::REQUIRED, '迁移名称')
            ->setHelp(sprintf('%s数据库迁移创建命令%s', PHP_EOL, PHP_EOL));
        $this->addOption('connection', 'c', \think\console\input\Option::VALUE_REQUIRED, '要使用的数据库连接.');

    }

    protected function execute(Input $input, Output $output){
        /** @var Creator $creator */
        $creator = $this->app->get('migration.creator');
        $className = $input->getArgument('name');
        $appName = $input->getOption('app');
        $path = $creator->create($className , $appName);
        $output->writeln('<info>created</info> .' . str_replace(getcwd(), '', realpath($path)));

    }
}